package com.mars.module.admin.controller;


import com.mars.common.enums.BusinessType;
import com.mars.common.response.PageInfo;
import com.mars.common.result.R;
import com.mars.common.util.ExcelUtils;
import com.mars.framework.annotation.Log;
import com.mars.framework.annotation.RateLimiter;
import com.mars.module.admin.entity.SysUserCaseInformation;
import com.mars.module.admin.request.SysUserCaseInformationRequest;
import com.mars.module.admin.service.ISysUserCaseInformationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

/**
 * 患者病例信息控制层
 *
 * @author mars
 * @date 2024-04-12
 */
@Slf4j
@AllArgsConstructor
@RestController
@Api(value = "患者病例信息接口管理",tags = "患者病例信息接口管理")
@RequestMapping("/admin/sysUserCaseInformation" )
public class SysUserCaseInformationController {

    private final ISysUserCaseInformationService iSysUserCaseInformationService;

    /**
     * 分页查询患者病例信息列表
     */
    @ApiOperation(value = "分页查询患者病例信息列表")
    @PostMapping("/pageList")
    public R<PageInfo<SysUserCaseInformation>> pageList(@RequestBody SysUserCaseInformationRequest SysUserCaseInformationRequest) {
        return R.success(iSysUserCaseInformationService.pageList(SysUserCaseInformationRequest));
    }

    /**
     * 获取患者病例信息详细信息
     */
    @ApiOperation(value = "获取患者病例信息详细信息")
    @GetMapping(value = "/query/{id}")
    public R<SysUserCaseInformation> detail(@PathVariable("id") Long id) {
        return R.success(iSysUserCaseInformationService.getById(id));
    }

    /**
     * 新增患者病例信息
     */
    @Log(title = "新增患者病例信息", businessType = BusinessType.INSERT)
    @RateLimiter
    @ApiOperation(value = "新增患者病例信息")
    @PostMapping("/add")
    public R<Void> add(@RequestBody SysUserCaseInformationRequest SysUserCaseInformationRequest) {
        iSysUserCaseInformationService.add(SysUserCaseInformationRequest);
        return R.success();
    }

    /**
     * 修改患者病例信息
     */
    @Log(title = "修改患者病例信息", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改患者病例信息")
    @PostMapping("/update")
    public R<Void> edit(@RequestBody SysUserCaseInformationRequest SysUserCaseInformationRequest) {
        iSysUserCaseInformationService.update(SysUserCaseInformationRequest);
        return R.success();
    }

    /**
     * 删除患者病例信息
     */
    @Log(title = "删除患者病例信息", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除患者病例信息")
    @PostMapping("/delete/{ids}")
    public R<Void> remove(@PathVariable Long[] ids) {
        iSysUserCaseInformationService.deleteBatch(Arrays.asList(ids));
        return R.success();
    }

    /**
    * 导出患者病例信息
    *
    * @param response response
    * @throws IOException IOException
    */
    @PostMapping(value = "/export")
    public void exportExcel(HttpServletResponse response,@RequestBody SysUserCaseInformationRequest SysUserCaseInformationRequest) throws IOException {
        List<SysUserCaseInformation> list = iSysUserCaseInformationService.list(SysUserCaseInformationRequest);
        ExcelUtils.exportExcel(list, SysUserCaseInformation.class, "患者病例信息信息", response);
    }
}
